package com.app.micaihu.view.main.game.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.game.GameRaidersEntity;
import com.app.micaihu.bean.game.ViewGameBigVideo;
import com.app.micaihu.bean.game.ViewGameNoImg;
import com.app.micaihu.bean.game.ViewGameOneImg;
import com.app.micaihu.bean.game.ViewGameSmallVideo;
import com.app.micaihu.bean.game.ViewGameThreeImg;
import com.app.micaihu.configure.TypeConstant;

import java.util.List;

/**游戏攻略适配器
 * Created by linkai on 2017/3/13.
 */
public class GameRaidersAdapter extends AppBaseAdapter<GameRaidersEntity> implements View.OnClickListener {

    private static final int GAME_NO_IMAGE = 0;//没有图片
    private static final int GAME_ONE_IMAGE = 1;// 一个图片
    private static final int GAME_THREE_IMAGE = 2;// 三个图片
    private static final int GAME_SMALL_VIDEO = 3;// 小视频
    private static final int GAME_BIG_VIDEO = 4;// 大视频
    private static final int DEFAULT = 5;//没有匹配到类型

    private boolean isAbout;//是否是相关新闻


    public GameRaidersAdapter(List<GameRaidersEntity> list, Context context) {
        super(list, context);
    }

    public GameRaidersAdapter(List<GameRaidersEntity> list, Context context,boolean isAbout) {
        super(list, context);
        this.isAbout = isAbout;
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {

        GameRaidersEntity gameRaidersEntity = list.get(position);
        if(gameRaidersEntity == null){
            gameRaidersEntity = new GameRaidersEntity();
        }
        int type = getItemViewType(position);
        if(convertView == null){
            switch (type){
                case GAME_NO_IMAGE:{
                    convertView = inflater.inflate(R.layout.item_gamelist_no_img,null);
                    ViewGameNoImg viewGameNoImg = new ViewGameNoImg(convertView);
                    if(isAbout){
                        convertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    }
                    viewGameNoImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_ONE_IMAGE:{
                    convertView = inflater.inflate(R.layout.item_gamelist_one_img,null);
                    if(isAbout){
                        convertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    }
                    ViewGameOneImg viewGameOneImg = new ViewGameOneImg(convertView);
                    viewGameOneImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_THREE_IMAGE:{
                    convertView = inflater.inflate(R.layout.item_gamelist_three_img,null);
                    ViewGameThreeImg viewGameThreeImg = new ViewGameThreeImg(convertView);
                    if(isAbout){
                        convertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    }
                    viewGameThreeImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_SMALL_VIDEO:{
                    convertView = inflater.inflate(R.layout.item_gamelist_small_video,null);
                    ViewGameSmallVideo viewGameVideoSmallImg = new ViewGameSmallVideo(convertView);
                    if(isAbout){
                        convertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    }
                    viewGameVideoSmallImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_BIG_VIDEO:{
                    convertView = inflater.inflate(R.layout.item_gamelist_big_video,null);
                    ViewGameBigVideo viewGameBigVideo = new ViewGameBigVideo(convertView);
                    if(isAbout){
                        convertView.setBackgroundResource(R.drawable.item_aboutnewslist_bg_selector);
                    }
                    viewGameBigVideo.loadData(gameRaidersEntity);
                    break;
                }
                default:
                    convertView = inflater.inflate(R.layout.item_layout_gone,null);
                    break;
            }
        }else{
            switch (type){
                case GAME_NO_IMAGE:{
                    ViewGameNoImg viewGameNoImg = (ViewGameNoImg) convertView.getTag();
                    viewGameNoImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_ONE_IMAGE:{
                    ViewGameOneImg viewGameOneImg = (ViewGameOneImg) convertView.getTag();
                    viewGameOneImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_THREE_IMAGE:{
                    ViewGameThreeImg viewGameThreeImg = (ViewGameThreeImg) convertView.getTag();
                    viewGameThreeImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_SMALL_VIDEO:{
                    ViewGameSmallVideo viewGameVideoSmallImg = (ViewGameSmallVideo) convertView.getTag();
                    viewGameVideoSmallImg.loadData(gameRaidersEntity);
                    break;
                }
                case GAME_BIG_VIDEO:{
                    ViewGameBigVideo viewGameBigVideo = (ViewGameBigVideo) convertView.getTag();
                    viewGameBigVideo.loadData(gameRaidersEntity);
                    break;
                }
                default:
                    convertView = inflater.inflate(R.layout.item_layout_gone,null);
                    break;
            }
        }
        return convertView;
    }

    @Override
    public int getItemViewType(int position) {
        GameRaidersEntity gameRaidersEntity = list.get(position);
        if(gameRaidersEntity == null){
            return DEFAULT;
        }
        switch (gameRaidersEntity.getArticleType()){
            case TypeConstant.GAME_RAIDERS_TEXT:{
                if(gameRaidersEntity.getArticleThumb() == null || gameRaidersEntity.getArticleThumb().size() <= 0){
                    return GAME_NO_IMAGE;
                }else if(gameRaidersEntity.getArticleThumb().size() < 3 && gameRaidersEntity.getArticleThumb().size() > 0){
                    return GAME_ONE_IMAGE;
                }else{
                    return GAME_THREE_IMAGE;
                }
            }
            case TypeConstant.GAME_RAIDERS_VIDEO:{
                if(gameRaidersEntity.getArticleThumb() == null || gameRaidersEntity.getArticleThumb().size() == 0){
                    return DEFAULT;
                }else if(TypeConstant.NEWS_UI_SMALL_IMG.equals(gameRaidersEntity.getUiType())){
                    return GAME_SMALL_VIDEO;
                }else if(TypeConstant.NEWS_UI_BIG_ONE_IMG.equals(gameRaidersEntity.getUiType())
                        || TypeConstant.NEWS_UI_BIG_TWO_IMG.equals(gameRaidersEntity.getUiType())){
                    return GAME_BIG_VIDEO;
                }else {
                    return DEFAULT;
                }
            }
        }
        return DEFAULT;
    }

    @Override
    public int getViewTypeCount() {
        return 7;
    }

    @Override
    public void onClick(View v) {
        if(v == null){
            return;
        }

    }


}
